<template>
  <div>
    <!-- 搜索 -->
    <TopFilter
      ref="commonTopFilter"
      :list="topFilterInit"
      :cols="3"
      labelWidth="90"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
      @resetChange="resetHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      columnsRef="notification_maintain_index_01"
      :onColumnsChange="columns => (this.columns = columns)"
    >
<!--      <template slot="controls">-->
<!--        <multiuse-button type="primary" :click="exportFileBtn.bind(this)">导出</multiuse-button>-->
<!--      </template>-->
    </FilterTable>
    <Drawer :visible.sync="visibleAdd" :title="title" destroyOnClose width="60%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <AddForm @close="closeAdd" @save="saveAdd" :type="type" :row="row"></AddForm>
    </Drawer>
    <BaseDialog :visible.sync="selectDelearFlag" title="服务中心选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DealerList @close="Delearclose" @save="Delearsave" selectionType="multiple" />
    </BaseDialog>
  </div>
</template>
<script>
import AddForm from './AddForm.vue';
import {getRefusalToClaim ,getListForExport}from '@/api/claim/factory/refusalToClaim';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils/index';
import { authority } from '@/utils/authMixin';
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
export default {
  name: "refusalToClaim",
  mixins: [authority, dictionary],
  components: {
    AddForm,
    DealerList
  },
  data() {
    return {
      topFilterInit: this.topFilterInitFun(),
      fetchApi: getRefusalToClaim,//api 接口 table请求数据入口
      fetchParams: {isQuery:1},
      selectDelearFlag: false,
      type:'',
      title:'',
      dealerData: [],
      row:{},
      visibleAdd:false,
      columns: this.creatHeader()
    };
  },
  methods: {
    topFilterInitFun() {
      return [
        {type: 'INPUT', label: '拒赔申诉单号', fieldName: 'claimRefusalNo', placeholder: '请输入', initialValue: ''},
        {
          type: 'INPUT',
          label: '服务中心',
          render: (p) => {
            return (
              <div>
                <el-select v-model={this.selectDealerData} disabled={true} multiple placeholder="请选择">
                  {this.dealerData.map((item) => (
                    <el-option key={item.dealerCode} label={item.dealerShortname} value={item.dealerCompanyCode} />
                  ))}
                </el-select>
                <multiuse-button style="position: absolute;right: 0;height:100%" icon="el-icon-search" onClick={() => this.selectDelearFlag = true} />
              </div>
            );
          },
        },
        {type: 'INPUT', label: '索赔单号', fieldName: 'cmsClaimNo', placeholder: '请输入', initialValue: ''},
        {type: 'RANGE_DATE', label: '申诉日期', fieldName: 'complainDataFrom|complainDataTo', placeholder: '请输入', initialValue: '',dateType: 'daterange', valueFormat: 'yyyy-MM-dd'},
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'state',
          placeholder: '请输入',
          initialValue: '',
          itemList:this.createDictList('5503',[55031001,55031005,55031006,55031007])
        },
        {type: 'SELECT', label: '申诉类型', fieldName: 'complainType', placeholder: '请输入', initialValue: '',itemList:this.createDictList('5568')}
      ];},
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 110,
          sorter: true,
          fixed: 'left',
          render: props => {
            let disabled = props.row.state != 55031002? true : false;
            return (
              <div>
                <el-button size="mini" disabled={disabled} type="text"  onClick={() => this.examine(props.row, 'edit')} >
                  审核
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text"  onClick={() => this.examine(props.row, 'detailed') } disabled={false}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {title: '拒赔申诉单号', dataIndex: 'claimRefusalNo', sorter: true, showOverflowTooltip: true},
        {title: '服务中心代码', dataIndex: 'dealerCode', sorter: true},
        {title: '服务中心简称', dataIndex: 'dealerName', sorter: true},
        {
          title: '状态',
          dataIndex: 'state',
          sorter: true,
          showOverflowTooltip: true,
          render: props => {
            return <div>{this.createDictText(props.row.state, '5503')}</div>;
          }
        },
        {
          title: '申诉类型',
          dataIndex: 'complainType',
          sorter: true,
          showOverflowTooltip: true,
          render: props => {
            return <div>{this.createDictText(props.row.complainType, '5568')}</div>;
          }},
        {title: '索赔单号', dataIndex: 'cmsClaimNo', sorter: true, showOverflowTooltip: true,},
        {
          title: '索赔类型',
          dataIndex: 'cmsClaimType',
          sorter: true,
          showOverflowTooltip: true,
          render: props => {
            return <div>{this.createDictText(props.row.cmsClaimType, '5510')}</div>;
          }
        },
        {title: 'VIN', dataIndex: 'vin', sorter: true, showOverflowTooltip: true},
        {title: '车型名称', dataIndex: 'modelName', sorter: true, showOverflowTooltip: true},
        {title: '申诉人', dataIndex: 'complainBy', sorter: true, showOverflowTooltip: true},
        {title: '申诉日期', dataIndex: 'complainData', sorter: true,showOverflowTooltip: true, dateFormat: 'yyyy-MM-dd HH:mm'},
        {title: '审核人', dataIndex: 'checkBy', sorter: true, showOverflowTooltip: true},
        {title: '审核日期', dataIndex: 'checkData', sorter: true,showOverflowTooltip: true, dateFormat: 'yyyy-MM-dd HH:mm'},
      ]},
    newlyAdded(type) {
      this.title = '新增';
      this.type = type;
      this.visibleAdd = true;
    },
    examine(row, type) {
      this.title = type == 'edit'?'拒赔申诉审核':'拒赔申诉明细';
      this.type = type;
      this.row = row;
      this.visibleAdd = true;
    },
    closeAdd(rData) {
      this.visibleAdd = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = {...this.fetchParams};
      }
    },
    Delearclose() {
      this.selectDelearFlag = false;
    },

    Delearsave(obj) {
      console.log('选择数据传递', obj);
      this.dealerData = obj;
      this.selectDealerData = [];
      obj.forEach(item => {
        this.selectDealerData.push(item.dealerCode);
      });
      this.selectDelearFlag = false;
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    },
    //导出
    async exportFileBtn() {
      let params = { ...this.fetchParams};
      console.log(params, '导出::');
      let res = await getListForExport(params);
      console.log(res.data, '导出::');
      try {
        exportExcelFile(res.data, '拒赔申诉审核');
      } catch (e) {
        console.log(e, '错误::');
      }
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val,{dealerCompanyCode: this.selectDealerData.length ? this.selectDealerData : null,isQuery:1});
    },
    resetHandle(val) {
      this.dealerData = [];
      this.selectDealerData = [];
      this.fetchParams = {};
    },
    //展开收起时触发
    collapseHandle() {

    }
  }
};
</script>
